<meta title="新增宝贝" args="item" width="700px"/>
<style>
    .sellerPromotionItemAddForm th {
        text-align: right;
    }
</style>
<form class="p" s="form,nda,datac,valid" s-data="item" id="form" method="post" action="/api/sellerPromotionItem">
    <table class="table table-bordered table-stripped sellerPromotionItemAddForm">
        <tr>
            <th style="width: 100px;">宝贝图片：</th>
            <td s="tpl" colspan="3">
                {%$.each(this.imgList, function() {%}
                <img src="{%=this%}" style="width: 60px;height: 60px; float: left; margin-right: 5px; margin-bottom: 5px;" />
                <input autocomplete="off" type="hidden" name="imgs" value="{%=this%}" />
                {%})%}
                <input autocomplete="off" type="hidden" name="picUrl" value="{%=this.imgList[0]%}" />
                <input autocomplete="off" type="hidden" name="ecomPlat" value="{%=this.ecomPlat%}" />
            </td>
        </tr>
        <tr>
            <th style="width: 100px;">宝贝名：</th>
            <td colspan="3">
                <input autocomplete="off" type="text" name="title" s-valid-error="require()" class="form-control" />
            </td>
        </tr>
        <tr>
            <th style="width: 100px;">宝贝链接：</th>
            <td colspan="3" s="tpl" style="word-break: break-all">
                <a href="{%=this.sourceItemUrl%}" target="_blank" external>{%=this.sourceItemUrl%}</a>
                <input autocomplete="off" type="hidden" name="sourceItemUrl" value="{%=this.sourceItemUrl%}" s-valid-error="require()" class="form-control" />
            </td>
        </tr>
        <tr>
            <th style="width: 100px;">搜索关键字：</th>
            <td colspan="3">
                <input autocomplete="off" type="text" name="keywords" class="form-control" s-valid-error="require()"/>
            </td>
        </tr>
        <tr>
            <th style="width: 100px;">卖家：</th>
            <td style="width: 250px;">
                <input autocomplete="off" type="text" name="shopTitle" s-valid-error="require()" class="form-control" />
            </td>
            <th style="width: 100px;">分类：</th>
            <td style="width: 250px;">
                <select class="form-control" name="shopcatId" s-build="S.get('/api/shopcat/list/0')" s="select">

                </select>
            </td>
        </tr>
        <tr>
            <th style="width: 100px;">原售价：</th>
            <td >
                <input autocomplete="off" type="text" name="originPrice" s-valid-error="require(),number(),min(0)" class="form-control" />
            </td>
            <th style="width: 100px;">返现金额：</th>
            <td >
                <input autocomplete="off" type="text" name="rebateFee" placeholder="如果返现金额不填写或者为0，返现金额默认为原售价金额" s-valid-error="require(),number(),min(0)" class="form-control" />
            </td>
        </tr>
        <tr>
            <th style="width: 100px;">日放单数量：</th>
            <td >
                <input autocomplete="off" type="text" name="dayLimitNum" s-valid-error="require(),number(),min(1)" class="form-control" placeholder="输入商品的数量"/>
            </td>
            <th style="width: 100px;">默认快递：</th>
            <td>
                <input autocomplete="off" type="text" name="logisticsCompany" s-valid-error="require()" class="form-control" />
            </td>
        </tr>
        <tr>
            <th style="width: 100px;">开始日期：</th>
            <td colspan="3">
                <input autocomplete="off" type="text" name="startTime" s-valid-error="require()" class="form-control" s="datetimepicker"/>
            </td>
        </tr>
        <tr>
            <th style="width: 100px;">提示截图：</th>
            <td colspan="3">
                <input autocomplete="off" type="button" class="btn btn-xs" value="上传截图" s-click="selectScreenshots()" />
                <div class="screenshots-list clearfix" s="tpl" id="screenshotPanel">
                    {%$.each(this.screenshotList || [], function() {%}
                    <div class="screenshot-pic">
                        <img src="{%=this.url%}" />
                        <input autocomplete="off" type="hidden" class="screenshotList" value="{%=this.key%}" name="screenshotList" />
                        <a href="javascript:;" class="pic-remove" s-click="this.node.parent().remove()">&times;</a>
                    </div>
                    {%})%}
                </div>
            </td>
        </tr>
        <tr>
            <th style="width: 100px;">商品详情：</th>
            <td colspan="3">
                <textarea class="form-control" name="description" rows="5"></textarea>
            </td>
        </tr>
    </table>
</form>
<style>
    .screenshot-pic {
        float: left;
        width: 200px;
        height: 200px;
        margin-right: 5px;
        margin-bottom: 5px;
        border: 1px solid #ddd;
        position: relative;
    }
    .screenshot-pic img {
        max-width: 100%;
        max-height: 100%;
    }

    .pic-remove {
        position: absolute;
        top: 2px;
        right: 2px;
        color: #fb4748;
        text-align: center;
        line-height: 10px;
        font-size: 20px;
    }
</style>
<script>
    if(item.id) {
        $form.node.attr("method", "put").attr("action", "/api/sellerPromotionItem/" + item.id)
        S.meta.title = "编辑宝贝"
    }
    S.meta.btns = [
        {
            name: "保存",
            style: "btn btn-primary",
            click: function() {
                return $form.submit().done(function(rs) {
                    S.close(rs);
                })
            }
        },
        {
            name: "取消",
            style: "btn btn-default",
            click: function() {
                S.close();
            }
        }
    ]

    function selectScreenshots() {
        S.popupOpen("/oss/objects-selector.html", {prefix: 'user/' + item.userId}).done(function(datas) {
            if(datas) {
                $screenshotPanel.appendData({
                    screenshotList: datas
                })
            }
        })
    }
</script>